package com.Home.digital_life;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;

public class Upload {
	public static void TcpRun(String url, int port, String filepath,
			byte[] commond) {
		try {
			Socket socket = new Socket(url, port);
			DataInputStream inputstream = new DataInputStream(socket.getInputStream());
			DataOutputStream outputstream = new DataOutputStream(socket.getOutputStream());
			byte buffer[] = new byte[8 * 1024];
			int temp = 0;

			outputstream.write(commond);

			while ((temp = inputstream.read(buffer)) != -1) {
				outputstream.write(buffer, 0, temp);
			}
			outputstream.flush();
			inputstream.close();
			socket.close();
		} /*
		 * catch (UnknownHostException e) { // TODO Auto-generated catch block
		 * e.printStackTrace(); }
		 */catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public static void TcpRun(String url, int port, byte[] commond) {
		try {
			Socket socket = new Socket(url, port);
			OutputStream outputstream = socket.getOutputStream();
			outputstream.write(commond);
			outputstream.flush();
			socket.close();
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public static void TcpRun(String url, int port, byte[] commond, byte[] sn) {
		try {
			Socket socket = new Socket(url, port);
			OutputStream outputstream = socket.getOutputStream();
			outputstream.write(commond);
			outputstream.write(sn);
			outputstream.flush();
			socket.close();
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
